// pages/inmyschool/inmyschool.js
import urls from '../../utils/urls.js'
import loginFn from '../../utils/login.js'
var app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		alldetail: '', //所有的详情
		allClass: [], //所有课程
		allTeacher: [], //所有教师
		imgUrls: [],
		schoolId: '',
	},
	// 编辑
	godetail: function(e) {
		wx.navigateTo({
			url: '/pages/institutions/institutions?schoolId=' + e.currentTarget.dataset.id,
		})

	},
	gocourseDetail: function(e) {
		console.log(e, '52013145201314')
		let course = e.currentTarget.dataset.id
		wx.navigateTo({
			url: '/pages/classdetail/index?courseId=' + course,

		});

	},
	coursebySchool: function() {
		let that = this
		var coursebySchool = loginFn()
		coursebySchool.schoolId = this.data.schoolId
		wx.request({
			url: urls.coursebySchool,
			data: coursebySchool,
			success: function(res) {
				console.log(res, '老師656565656老師')
				that.setData({
					activityList: res.data.data
				})
			}
		})
	},
	schoolUrl: function() {
		let that = this;
		app.request({
			url: 'school/detail',
			data: {
				schoolId: that.data.schoolId
			},
			sCallback:(res) => {
				if(res.code == 1) {
					var imgUrls = []
					imgUrls.push(res.data.logoUrl)

					for (var i = 0; i < res.data.schoolImages.length; i++) {
						imgUrls.push(res.data.schoolImages[i].img)
					}

					that.setData({
						alldetail: res.data,
						imgUrls: imgUrls
					})
				}
			}
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		console.log('options:',options);
		var that = this;
		that.setData({
			schoolId: options.schoolId
		})
	},


	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

		this.schoolUrl()
		this.coursebySchool()
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {
		this.setData({
			sharetip: false
		})
		return {
			title: this.data.alldetail.schoolName+'欢迎您！',
			path: '/pages/institufirst/index?schoolId='+this.data.alldetail.schoolId,
			imgUrl: this.data.alldetail.logoUrl,
			success: (res) => {
				console.log("转发成功", res);
			},
			fail: (res) => {
				console.log("转发失败", res);
			}
		}
	},
	shareFn: function() { //分享弹框
		this.setData({
			sharetip: true
		})
	},
	shareCircle: function() { //分享到朋友圈
		wx.navigateTo({
			url: '/pages/share/index?type=school&from=main',
		})
	},
	hideMask(){
		this.setData({
			sharetip: false
		})
	}
})
